home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / STRINGS.SWG / 0063_Upper-Lower Strings.pas < prev    next >
Pascal/Delphi Source File  |  1993-11-02  |  4KB  |  147 lines

  1. {
  2. FRED JOHNSON
  3.  
  4. After noticing the compiler error,  Arthur Choi said...
  5.  
  6. >How do I upcase a String, For use With
  7. >a ReadLn?
  8. AC>Simple as possible, please... thanx
  9.  
  10. {More than you wanted, but very useful}
  11. Uses String_h;
  12.  
  13. Var
  14.   sData : String;
  15. begin
  16.   sData := 'fred';
  17.   Writeln('toupper  ', toupper(@sData)^);
  18.   Writeln('original ', sData);
  19.   Writeln('strupr   ', strupr(@sData)^);
  20.   Writeln('original ', sData);
  21.  
  22.   Writeln('tolower  ', tolower(@sData)^);
  23.   Writeln('original ', sData);
  24.   Writeln('strlwr   ', strlwr(@sData)^);
  25.   Writeln('original ', sData);
  26. end.
  27.  
  28. {---- String_h.pas.tpu ---}
  29. {*******************************************************************!HDR**
  30. ** Module Name: String_h.pas
  31. ** $LogFile:$
  32. ** $Revision:$
  33. ** $Author:$
  34. ** System Module Purpose:
  35. ** Public Functions Within this module:
  36. ** Global usage:
  37. ** Special notes:
  38. ** $Log$
  39. ** Initial revision.
  40. ** Initial revision. 10/05/93 19:35
  41. ********************************************************************!end*}
  42. Unit String_h;
  43.  
  44. Interface
  45. Type
  46.    spStringPtr = ^String;
  47.  
  48. {-------------------------------------------------------------------!HDR--
  49. ** Function Name: toupper();
  50. ** Description  : converts String to upper case
  51. ** Returns      : Pointer to an uppercase String
  52. ** Calls        : length, upcase
  53. ** Special considerations:
  54. ** Modification history:
  55. ** Created: 10/05/93 19:28}
  56. Function toupper(String_or_Char : spStringPtr) : spStringPtr;
  57.  
  58. {-------------------------------------------------------------------!HDR--
  59. ** Function Name: tolower();
  60. ** Description  : converts a String to lower case
  61. ** Returns      : Pointer to a lower Case String
  62. ** Calls        : length, ord, length
  63. ** Special considerations:
  64. ** Modification history:
  65. ** Created: 10/05/93 19:28}
  66. Function tolower(String_or_Char : spStringPtr) : spStringPtr;
  67.  
  68. {-------------------------------------------------------------------!HDR--
  69. ** Function Name: strupr
  70. ** Description  : converts String and alters contents to uppercase
  71. ** Returns      : Pointer to uppercase String
  72. ** Calls        : upcase, length
  73. ** Special considerations:
  74. ** Modification history:
  75. ** Created: 10/05/93 19:28}
  76. Function strupr (String_or_Char : spStringPtr) : spStringPtr;
  77.  
  78. {-------------------------------------------------------------------!HDR--
  79. ** Function Name: strlwr
  80. ** Description  : converts String and alters contents to lower case
  81. ** Returns      : Pointer to lower Case String
  82. ** Calls        : ord, Char, length
  83. ** Special considerations:
  84. ** Modification history:
  85. ** Created: 10/05/93 19:28}
  86. Function strlwr (String_or_Char : spStringPtr) : spStringPtr;
  87.  
  88. Implementation
  89.  
  90. Function toupper(String_or_Char : spStringPtr) : spStringPtr;
  91. Var
  92.   byCounter : Byte;
  93. begin
  94.   toupper^[0] := String_or_Char^[0];
  95.   For byCounter := 1 to length(String_or_Char^) do
  96.     toupper^[byCounter] := upcase(String_or_Char^[byCounter]);
  97. end;
  98.  
  99. Function tolower(String_or_Char : spStringPtr) : spStringPtr;
  100. Var
  101.   byCounter : Byte;
  102. begin
  103.   tolower^[0] := String_or_Char^[0];
  104.   For byCounter := 1 to length(String_or_Char^) do
  105.   begin
  106.     if ord(String_or_Char^[byCounter]) in [65..90] then
  107.       tolower^[byCounter] := Char(ord(String_or_Char^[byCounter])+32);
  108.     else
  109.       tolower^[byCounter] := String_or_Char^[byCounter];
  110.   end;
  111. end;
  112.  
  113. Function strupr(String_or_Char : spStringPtr) : spStringPtr;
  114. Var
  115.   byCounter : Byte;
  116. begin
  117.   strupr^[0] := String_or_Char^[0];
  118.   For byCounter := 1 to length(String_or_Char^) do
  119.   begin
  120.     strupr^[byCounter] := upcase(String_or_Char^[byCounter]);
  121.     String_or_Char^[byCounter] := upcase(String_or_Char^[byCounter]);
  122.   end;
  123. end;
  124.  
  125. Function strlwr(String_or_Char : spStringPtr) : spStringPtr;
  126. Var
  127.   byCounter : Byte;
  128. begin
  129.   strlwr^[0] := String_or_Char^[0];
  130.   For byCounter := 1 to length(String_or_Char^) do
  131.   begin
  132.     if ord(String_or_Char^[byCounter]) in [65..90] then
  133.     begin
  134.       strlwr^[byCounter] := Char(ord(String_or_Char^[byCounter])+32);
  135.       String_or_Char^[byCounter] := Char(ord(String_or_Char^[byCounter])+32);
  136.     end
  137.     else
  138.     begin
  139.       strlwr^[byCounter] := String_or_Char^[byCounter];
  140.       String_or_Char^[byCounter] := String_or_Char^[byCounter];
  141.     end;
  142.   end;
  143. end;
  144.  
  145. end.
  146.  
  147.